﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace jnxc.Web.caseinfo
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int caseid=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(caseid);
				}
			}
		}
			
	private void ShowInfo(int caseid)
	{
		jnxc.BLL.caseinfo bll=new jnxc.BLL.caseinfo();
		jnxc.Model.caseinfo model=bll.GetModel(caseid);
		this.lblcaseid.Text=model.caseid.ToString();
		this.txtuid.Text=model.uid.ToString();
		this.txtctype.Text=model.ctype;
		this.txtpid.Text=model.pid.ToString();
		this.txthid.Text=model.hid.ToString();
		this.txtcname.Text=model.cname;
		this.txtsid.Text=model.sid.ToString();
		this.txtvictim.Text=model.victim;
		this.txtbdes.Text=model.bdes;
		this.txtmdes.Text=model.mdes;
		this.txtades.Text=model.ades;
		this.txtcstate.Text=model.cstate.ToString();
		this.txtpindex.Text=model.pindex.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(!PageValidate.IsNumber(txtuid.Text))
			{
				strErr+="管理人格式错误！\\n";	
			}
			if(this.txtctype.Text.Trim().Length==0)
			{
				strErr+="分类农林不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtpid.Text))
			{
				strErr+="植物格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txthid.Text))
			{
				strErr+="有害生物格式错误！\\n";	
			}
			if(this.txtcname.Text.Trim().Length==0)
			{
				strErr+="项目名称不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtsid.Text))
			{
				strErr+="标准地格式错误！\\n";	
			}
			if(this.txtvictim.Text.Trim().Length==0)
			{
				strErr+="受害描述不能为空！\\n";	
			}
			if(this.txtbdes.Text.Trim().Length==0)
			{
				strErr+="前描述不能为空！\\n";	
			}
			if(this.txtmdes.Text.Trim().Length==0)
			{
				strErr+="中描述不能为空！\\n";	
			}
			if(this.txtades.Text.Trim().Length==0)
			{
				strErr+="后描述不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtcstate.Text))
			{
				strErr+="状态格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtpindex.Text))
			{
				strErr+="防效指数格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int caseid=int.Parse(this.lblcaseid.Text);
			int uid=int.Parse(this.txtuid.Text);
			string ctype=this.txtctype.Text;
			int pid=int.Parse(this.txtpid.Text);
			int hid=int.Parse(this.txthid.Text);
			string cname=this.txtcname.Text;
			int sid=int.Parse(this.txtsid.Text);
			string victim=this.txtvictim.Text;
			string bdes=this.txtbdes.Text;
			string mdes=this.txtmdes.Text;
			string ades=this.txtades.Text;
			int cstate=int.Parse(this.txtcstate.Text);
			int pindex=int.Parse(this.txtpindex.Text);


			jnxc.Model.caseinfo model=new jnxc.Model.caseinfo();
			model.caseid=caseid;
			model.uid=uid;
			model.ctype=ctype;
			model.pid=pid;
			model.hid=hid;
			model.cname=cname;
			model.sid=sid;
			model.victim=victim;
			model.bdes=bdes;
			model.mdes=mdes;
			model.ades=ades;
			model.cstate=cstate;
			model.pindex=pindex;

			jnxc.BLL.caseinfo bll=new jnxc.BLL.caseinfo();
			bll.Update(model);
			jnxc.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
